package com.yiquan.video.dao;

import com.yiquan.video.pojo.VideoBehave;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.*;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.QueryHint;

import static org.hibernate.jpa.QueryHints.HINT_COMMENT;

/**
 * @author Tyrone
 * @date 2021/12/31 14:24
 */
public interface VideoBehaveDao extends JpaRepository<VideoBehave,Long>, JpaSpecificationExecutor<VideoBehave> {

    @Query(nativeQuery = true,value = "select * from yiquan_video_behave where operate = ?3 and video_id = ?1 and user_id =?2")
    VideoBehave findOneByVideoIdAndUserIdAndOperate(Long videoId, Long userId, Integer operate);

    @Query(nativeQuery = true,value = "delete from yiquan_video_behave where operate = ?3 and video_id = ?1 and user_id =?2")
    @Modifying
    @Transactional
    void deleteByVideoIdAndUserIdAndOperate(Long videoId, Long userId, Integer operate);

    @Query(nativeQuery = true,value = "select count(*) from yiquan_video where video_id = ?1 and operate = ?2")
    Integer countByVideoIdAndOperate(Long videoId, Integer operate);

//    @QueryHints(value = { @QueryHint(name = HINT_COMMENT, value = "a query for pageable")})
//    @Query(value = " select * from student",nativeQuery = true)
//    Page<VideoBehave> getPageList(Pageable pageable);
}
